/*
__token => session => initiaUserInfo  | getUserInfo Api https://fxg.jinritemai.com/ffa/g/create  | Window.defaultData
_lid: String(Date.now()).substr(5) + String(Math.random()).substr(2, 4)
_bid: 固定的值 不同接口不同的值
msToken => cookie
*/
/**
 * 
 * @param {string} key CookieName
 * @returns 获取Cookie
 */
export const getCookie = (key) => {
  const cookieList = document.cookie.split("; ").map((res) => {
    let ck = res.split("=")
    return {
      name: ck[0],
      val: ck[1]
    }
  })
  const getfilter = cookieList.filter((ckl) => {
    return ckl.name === key
  })
  if (getfilter && getfilter.length) {
    return getfilter[0].val
  }
  console.log('getfilter', cookieList);
  throw new Error("获取的cookie不存在")
}
/**
 * 
 * @returns 获取参数 _lid 生成不同的数字字符串
 */
export const get_lid = () => {
  return String(Date.now()).substr(5) + String(Math.random()).substr(2, 4)
}

/**
 * 
 * @returns 获取__token
 * @return {
 *  userInfo: object ,
 *  __token: string
 * }
 */
export const get__token = () => {
  const sessionUserInfo = sessionStorage.getItem('initialUserInfo')
  const userInfo = JSON.parse(sessionUserInfo).data
  return {
    userInfo,
    __token: userInfo && userInfo.token
  }
}